import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/components/yt_text_style.dart';
import 'package:yt_devops/pages/site/site_setting/siet_elec_price_setting/add_mains_electricity_price/views/effective_data_widget.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'package:yt_devops/utils/brn_row1_delegate.dart';

/**
 *
 * @Description TODO
 * @Author liuer
 * @CreateTime 2024年03月26日 17:51
 */
class StoreStagePriceWidget extends StatelessWidget {
  final BuildContext context;
  final String title;
  final String startTime;
  final String endTime;
  final String priceString;
  final String electricityTypeSting;
  final bool isDelete;
  final Function(String startDateTime, String endDateTime) timeChooseCallBack;
  final Function() btnClickCallBack;
  final Function(String str) priceChangeCallBack;
  final Function(String) typeClickCallBack;

  const StoreStagePriceWidget(
      this.context,
      this.title,
      this.startTime,
      this.endTime,
      this.priceString,
      this.electricityTypeSting,
      this.timeChooseCallBack,
      this.btnClickCallBack,
      this.priceChangeCallBack,
      this.typeClickCallBack,
      {this.isDelete = false,
      Key? key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    GetStorage storage = GetStorage();
    String monetaryUnitName = storage.read('monetaryUnitName')??'元';
    if(monetaryUnitName == '元' || monetaryUnitName == '¥'){
      monetaryUnitName = ResKey.yuan.tr;
    }
    TextEditingController textFieldController = TextEditingController();
    textFieldController.text = priceString;
    String type = '';
    Log.d('electricityTypeSting===' + electricityTypeSting.toString());
    if (electricityTypeSting == '0') {
      type = ResKey.siteSettingElectricityShape.tr;
    } else if (electricityTypeSting == '1') {
      type = ResKey.siteSettingElectricityPeak.tr;
    } else if (electricityTypeSting == '2') {
      type = ResKey.siteSettingElectricityAverage.tr;
    } else if (electricityTypeSting == '3') {
      type = ResKey.siteSettingElectricityValley.tr;
    }
    return SizedBox(
      height: 145,
      child: Column(
        children: [
          Gaps.vGap5,
          EffectiveDataWidget(
            context,
            title,
            startTime,
            endTime,
            (startDateTime, endDateTime) {
              timeChooseCallBack(startDateTime, endDateTime);
            },
            () {
              btnClickCallBack();
            },
            isShowHour: true,
            isDelete: isDelete,
            isEdit: true,
          ),
          Row(
            children: [
              Gaps.hGap16,
              Container(
                width: 90.w,
                child: Text(
                  ResKey.siteSettingElectricityElectrovalency.tr,
                  style: ytTextStyle(
                      fontWeight: FontWeight.normal,
                      color: Colour.otherTextColor,
                      fontSize: 14),
                ),
              ),
              // Gaps.hGap10,
              // const Spacer(),
              Container(

                decoration: const BoxDecoration(
                    color: Colour.backgroundColor,
                    borderRadius: BorderRadius.all(Radius.circular(4))),
                height: 32,
                width: 106.w,
                alignment: Alignment.center,
                child: TextField(
                  textAlign: TextAlign.center,
                  style: const TextStyle(
                      fontSize: 14, color: Colour.mainTextColor),
                  controller: textFieldController,
                  keyboardType:
                      const TextInputType.numberWithOptions(decimal: true),
                  decoration: InputDecoration(
                    border: InputBorder.none,
                    contentPadding: const EdgeInsets.only(bottom: 12),
                    hintText: ResKey.siteSettingElectricityElectrovalency.tr,
                    enabled: true,
                    hintStyle: const TextStyle(
                        fontSize: 14.0,
                        color: Colour.lightTextColor,
                        fontWeight: FontWeight.normal),
                  ),
                  onChanged: (String str) {
                    priceChangeCallBack(str);
                  },
                ),
              ),
              Gaps.hGap10,
              Container(
                padding: EdgeInsets.only(left: 4.w),
                // width: 169.w,
                child: Text(
                  '$monetaryUnitName/kWh',
                  style:
                      ytTextStyle(fontWeight: FontWeight.normal, fontSize: 14),
                ),
              )
            ],
          ),
          Row(children: [
            Gaps.hGap16,
            Container(
                width: 90.w,
                child: Text(
              ResKey.siteSettingElectricityPriceType.tr,
              style: ytTextStyle(
                  fontWeight: FontWeight.normal,
                  color: Colour.otherTextColor,
                  fontSize: 14),
            )),
            // const Spacer(),
            // Gaps.hGap10,
            GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () {
                showBottomPop([
                  ResKey.siteSettingElectricityShape.tr,
                  ResKey.siteSettingElectricityPeak.tr,
                  ResKey.siteSettingElectricityAverage.tr,
                  ResKey.siteSettingElectricityValley.tr
                ]);
                // typeClickCallBack();
              },
              child: Container(
                margin: EdgeInsets.only(top: 10),
                decoration: const BoxDecoration(
                    color: Colour.backgroundColor,
                    borderRadius: BorderRadius.all(Radius.circular(4))),
                height: 32,
                width: 106.w,
                alignment: Alignment.center,
                child: Text(
                  type,
                  style:
                      ytTextStyle(fontWeight: FontWeight.normal, fontSize: 14),
                ),
              ),
            ),
            // SizedBox(
            //   height: 32,
            //   width: 140.w,
            // ),
            Spacer(),
          ]),
          const Spacer(),
          // Container(
          //   height: 1,
          //   // margin: EdgeInsets.only(left: 16.w, right: 16.w),
          //   color: Colour.dividerColor,
          // ),
        ],
      ),
    );
  }

  ///弹出底部弹窗
  showBottomPop(List<String> list) {
    BrnMultiDataPicker(
      context: Get.context!,
      title: title,
      confirmClick: (indexList) {
        Log.d('indexList==' + indexList[0].toString());
        typeClickCallBack(indexList[0].toString());
      },
      delegate: Brn1RowDelegate(list),
    ).show();
  }
}
